/**
 * Autogenerated by Thrift Compiler (0.19.0)
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Thrift;
using Thrift.Collections;
using Thrift.Protocol;
using Thrift.Protocol.Entities;
using Thrift.Protocol.Utilities;
using Thrift.Transport;
using Thrift.Transport.Client;
using Thrift.Transport.Server;
using Thrift.Processor;


#nullable enable                 // requires C# 8.0
#pragma warning disable IDE0079  // remove unnecessary pragmas
#pragma warning disable IDE0017  // object init can be simplified
#pragma warning disable IDE0028  // collection init can be simplified
#pragma warning disable IDE1006  // parts of the code use IDL spelling
#pragma warning disable CA1822   // empty DeepCopy() methods still non-static

namespace QueryCat.Plugins.Sdk
{

  public partial class PluginData : TBase
  {

    public List<global::QueryCat.Plugins.Sdk.Function>? Functions { get; set; }

    public string Name { get; set; } = string.Empty;

    public string Version { get; set; } = string.Empty;

    public PluginData()
    {
    }

    public PluginData(List<global::QueryCat.Plugins.Sdk.Function>? @functions, string @name, string @version) : this()
    {
      this.Functions = @functions;
      this.Name = @name;
      this.Version = @version;
    }

    public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)
    {
      iprot.IncrementRecursionDepth();
      try
      {
        bool isset_functions = false;
        bool isset_name = false;
        bool isset_version = false;
        TField field;
        await iprot.ReadStructBeginAsync(cancellationToken);
        while (true)
        {
          field = await iprot.ReadFieldBeginAsync(cancellationToken);
          if (field.Type == TType.Stop)
          {
            break;
          }

          switch (field.ID)
          {
            case 1:
              if (field.Type == TType.List)
              {
                {
                  var _list20 = await iprot.ReadListBeginAsync(cancellationToken);
                  Functions = new List<global::QueryCat.Plugins.Sdk.Function>(_list20.Count);
                  for(int _i21 = 0; _i21 < _list20.Count; ++_i21)
                  {
                    global::QueryCat.Plugins.Sdk.Function _elem22;
                    _elem22 = new global::QueryCat.Plugins.Sdk.Function();
                    await _elem22.ReadAsync(iprot, cancellationToken);
                    Functions.Add(_elem22);
                  }
                  await iprot.ReadListEndAsync(cancellationToken);
                }
                isset_functions = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 2:
              if (field.Type == TType.String)
              {
                Name = await iprot.ReadStringAsync(cancellationToken);
                isset_name = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            case 3:
              if (field.Type == TType.String)
              {
                Version = await iprot.ReadStringAsync(cancellationToken);
                isset_version = true;
              }
              else
              {
                await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              }
              break;
            default: 
              await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken);
              break;
          }

          await iprot.ReadFieldEndAsync(cancellationToken);
        }

        await iprot.ReadStructEndAsync(cancellationToken);
        if (!isset_functions)
        {
          throw new TProtocolException(TProtocolException.INVALID_DATA);
        }
        if (!isset_name)
        {
          throw new TProtocolException(TProtocolException.INVALID_DATA);
        }
        if (!isset_version)
        {
          throw new TProtocolException(TProtocolException.INVALID_DATA);
        }
      }
      finally
      {
        iprot.DecrementRecursionDepth();
      }
    }

    public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
    {
      oprot.IncrementRecursionDepth();
      try
      {
        var tmp23 = new TStruct("PluginData");
        await oprot.WriteStructBeginAsync(tmp23, cancellationToken);
        var tmp24 = new TField();
        if((Functions != null))
        {
          tmp24.Name = "functions";
          tmp24.Type = TType.List;
          tmp24.ID = 1;
          await oprot.WriteFieldBeginAsync(tmp24, cancellationToken);
          await oprot.WriteListBeginAsync(new TList(TType.Struct, Functions.Count), cancellationToken);
          foreach (global::QueryCat.Plugins.Sdk.Function _iter25 in Functions)
          {
            await _iter25.WriteAsync(oprot, cancellationToken);
          }
          await oprot.WriteListEndAsync(cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((Name != null))
        {
          tmp24.Name = "name";
          tmp24.Type = TType.String;
          tmp24.ID = 2;
          await oprot.WriteFieldBeginAsync(tmp24, cancellationToken);
          await oprot.WriteStringAsync(Name, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        if((Version != null))
        {
          tmp24.Name = "version";
          tmp24.Type = TType.String;
          tmp24.ID = 3;
          await oprot.WriteFieldBeginAsync(tmp24, cancellationToken);
          await oprot.WriteStringAsync(Version, cancellationToken);
          await oprot.WriteFieldEndAsync(cancellationToken);
        }
        await oprot.WriteFieldStopAsync(cancellationToken);
        await oprot.WriteStructEndAsync(cancellationToken);
      }
      finally
      {
        oprot.DecrementRecursionDepth();
      }
    }

    public override bool Equals(object? that)
    {
      if (that is not PluginData other) return false;
      if (ReferenceEquals(this, other)) return true;
      return TCollections.Equals(Functions, other.Functions)
        && global::System.Object.Equals(Name, other.Name)
        && global::System.Object.Equals(Version, other.Version);
    }

    public override int GetHashCode() {
      int hashcode = 157;
      unchecked {
        if((Functions != null))
        {
          hashcode = (hashcode * 397) + TCollections.GetHashCode(Functions);
        }
        if((Name != null))
        {
          hashcode = (hashcode * 397) + Name.GetHashCode();
        }
        if((Version != null))
        {
          hashcode = (hashcode * 397) + Version.GetHashCode();
        }
      }
      return hashcode;
    }

    public override string ToString()
    {
      var tmp26 = new StringBuilder("PluginData(");
      if((Functions != null))
      {
        tmp26.Append(", Functions: ");
        Functions.ToString(tmp26);
      }
      if((Name != null))
      {
        tmp26.Append(", Name: ");
        Name.ToString(tmp26);
      }
      if((Version != null))
      {
        tmp26.Append(", Version: ");
        Version.ToString(tmp26);
      }
      tmp26.Append(')');
      return tmp26.ToString();
    }
  }

}
